from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Edge()
driver.get("http://baidu.com")
driver.maximize_window()
sleep(2)
# 刷新
driver.refresh()
sleep(2)
# 后退
driver.back()
sleep(2)
# 前进
driver.forward()
sleep(2)
search = driver.find_element(By.ID,'kw')
search.send_keys('自动化测试')
sleep(2)
search.send_keys(Keys.ENTER)
sleep(1)
# ActionChains(driver).context_click(search).perform()
# sleep(1)
# ActionChains(driver).double_click(search).click(search).perform()
search.send_keys(Keys.CONTROL,'a')
sleep(1)
search.send_keys(Keys.CONTROL,'c')
sleep(1)
set = driver.find_element(By.NAME,'tj_settingicon')
ActionChains(driver).move_to_element(set).perform()
sleep(1)
driver.find_element(By.XPATH,'//*[@id="u"]/div/a[2]/span').click()
sleep(2)
q1 = driver.find_element(By.ID,'adv_keyword')
q1.send_keys(Keys.CONTROL,'v')
sleep(1)
ActionChains(driver).double_click(q1).perform()
sleep(1)
q1.send_keys(Keys.CONTROL,'x')
sleep(1)
q2 = driver.find_element(By.NAME,'q2')
q2.send_keys(Keys.CONTROL,'v')
sleep(1)
# 时间
driver.find_element(By.XPATH,'//*[@id="adv-setting-gpc"]/div/div[1]/span').click()
sleep(1)
driver.find_element(By.XPATH,'//*[@id="adv-setting-gpc"]/div/div[2]/div[2]/p[4]').click()
sleep(1)
# 文档格式
driver.find_element(By.XPATH,'//*[@id="adv-setting-ft"]/div/div[1]/span').click()
sleep(1)
driver.find_element(By.XPATH,'//*[@id="adv-setting-ft"]/div/div[2]/div[2]/p[3]').click()
sleep(1)
# 站内搜索 百度
driver.find_element(By.XPATH,'//*[@id="adv-setting-7"]/input[1]').send_keys('百度')
sleep(1)
# 点击高级搜索
driver.find_element(By.XPATH,'//*[@id="adv-setting-8"]/input[2]').click()

sleep(5)